import openpyxl
import csv


def read_csv_rol(records, rol, csv_name="data.csv"):
    with open(csv_name)as f:
        f_csv = csv.reader(f)
        first = True
        for row in f_csv:
            if first:
                first = False
            else:
                records.append(float(row[rol-1]))
                # print(row[rol-1])


def write_to_excel_with_openpyxl(records, rol, head_row, save_excel_name="save.xlsx"):
    # 打开workbook
    wb = openpyxl.load_workbook(save_excel_name)
    # 打开sheet
    sheet = wb['1']
    # 写标题
    sheet.cell(1, rol).value = head_row
    # 写数据
    i = 2
    for record in records:
        sheet.cell(i, rol).value = record
        i += 1
    # 保存EXCEL
    wb.save(save_excel_name)
